import ApiClient, { RequestParams } from '../utils/ApiClient.ts';
import { TreeNode } from '../component/PickerCascader.tsx';

class UserRequest {
  // 登录
  public static Login(params: RequestParams) {
    return ApiClient.post<ILoginResponse>('wx/v1/user/userLogin', params);
  }

  // 获取验证码
  public static FetchSMS(params: RequestParams) {
    return ApiClient.post<any>('wx/v1/msg/sms', params);
  }

  // 更新用户信息
  public static UpdateUser(params: RequestParams) {
    return ApiClient.put<string>('wx/v1/user/setUserInfo', params);
  }

  // 更新用户手机号
  public static UpdateUserPhone(params: RequestParams) {
    return ApiClient.put<string>('wx/v1/user/setUserPhone', params);
  }

  // 获取地址列表
  public static ListShippingAddresses(params: RequestParams) {
    return ApiClient.get<IListShippingAddressesRes[]>('wx/v1/userHarvestAddress/listByUser', params);
  }

  // 获取地址详情
  public static GetAddressDetails(params: RequestParams) {
    return ApiClient.get<IGetAddressDetailsRes>('wx/v1/userHarvestAddress', params);
  }

  // 保存收货地址
  public static SaveShippingAddress(params: RequestParams) {
    return ApiClient.post<number>('wx/v1/userHarvestAddress', params);
  }

  // 修改收货地址
  public static EditShippingAddress(params: RequestParams) {
    return ApiClient.put<number>('wx/v1/userHarvestAddress', params);
  }

  // 删除收货地址
  public static DeleteShippingAddress(params: RequestParams) {
    return ApiClient.put('wx/v1/userHarvestAddress/delete', params);
  }

  // 获取小区列表
  public static ResidentialAddressList(params: RequestParams) {
    return ApiClient.get<IResidentialAddressListRes[]>('wx/v1/village/listByName', params);
  }

  /**
   * 获取楼栋层树
   * @param params
   * @constructor
   */
  public static BuildingTree(params: RequestParams) {
    return ApiClient.get<TreeNode[]>('wx/v1/villageArea/idNameTree', params);
  }

  /**
   * 获得紧急联系人
   * @param params
   * @constructor
   */
  public static GetUserContact(params: { userId: number }) {
    return ApiClient.get<IGetUserContactRes>('wx/v1/userContact', params);
  }

  /**
   * 修改紧急联系人
   * @param params
   * @constructor
   */
  public static UpdateUserContact(params: RequestParams) {
    return ApiClient.post('wx/v1/userContact/setUserContact', params);
  }

  /**
   * 是否开通邻里互助
   * @param params
   * @constructor
   */
  public static UpdateHelpFlag(params: RequestParams) {
    return ApiClient.put('wx/v1/userContact/setHelpFlag', params);
  }

  /**
   * 会员余额
   * @param params
   * @constructor
   */
  public static ListByCustomer(params: RequestParams) {
    return ApiClient.get<IListByCustomerRes[]>('wx/v1/member/listByCustomer', params);
  }

  /**
   * 获得积分
   * @param params
   * @constructor
   */
  public static GetPoints(params: RequestParams) {
    return ApiClient.get<number>('wx/v1/customerPointsRecord/getPoints', params);
  }

  /**
   * 积分账单中获得积分
   * @param params
   * @constructor
   */
  public static CountByMonth(params: RequestParams) {
    return ApiClient.get<{ expense: number; income: number }>('wx/v1/customerPointsRecord/countByMonth', params);
  }

  /**
   * 积分账单中获得积分列表
   * @param params
   * @constructor
   */
  public static PointsRecordList(params: RequestParams) {
    return ApiClient.get<IPointsRecordList>('wx/v1/customerPointsRecord/page', params);
  }
}

export default UserRequest;
